from django.shortcuts import render

# Create your views here.
from django.http import HttpResponse
from django.shortcuts import render
# from .models import Post
#
#
#
# def show_name(request):
#     context = {'name_list': Post.objects.all()}
#     return render(request, 'web01.html', context=context)

#
# def index(request):
#     return HttpResponse('Hello Django!')
#
#
# def web01(request):
#     return render(request, "web01.html")


#添加数据库数据
from django.shortcuts import render,HttpResponse
from new01 import models
def add_book(request):
     book = models.Book(name="华自传",price=300,publish="人人人出版社",pub_data="1812-01-18")
     book.save()
     return HttpResponse("<p>数据添加成功！</p>")


# #查找数据库数据
# from django.shortcuts import render,HttpResponse
# from new01 import models
#
# def add_book(request):
#
#     books = models.Book.objects.all()
#     print(books,type(books)) # QuerySet类型，类似于list，访问 url 时数据显示在命令行窗口中。
#     for i in books:
#         print(i.name)
#     return HttpResponse("<p>查找成功！</p>")


# #删除数据库数据
# from django.shortcuts import render,HttpResponse
# from new01 import models
#
# def add_book(request):
#
#     books = models.Book.objects.filter(pk=1).first().delete()
#     return HttpResponse(books)